<!-- 闪测类型表表单弹窗 -->
<form id="quicktestype-form" lay-filter="quicktestype-form" class="layui-form model-form" style="overflow:auto; height:500px;width:90%;">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">分类标题</label>
        <div class="layui-input-block">
            <input name="title" placeholder="请输入分类标题" type="text" class="layui-input" maxlength="20"  id="title"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <div>
            <label class="layui-form-label">标题修饰图片(建议气泡图，45px高，宽度随意)</label>
        </div>

        <div class="layui-input-block">
            <input type="hidden" name="titleImage"   id="uploadPath2" class="layui-input"     />
            <img id="uploadimg2" src="" width="100" />
            <button type="button" class="layui-btn"  id="uploadUrl2"   lay-filter="uploadFile">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">概述</label>
        <div class="layui-input-block">
            <input name="description" placeholder="请输入概述" type="text" class="layui-input" maxlength="20"  id="description"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图片(建议250*210)</label>
        <div class="layui-input-block">
            <input type="hidden" name="image"   id="uploadPath" class="layui-input"     />
            <img id="uploadimg" src="" width="100" />
            <button type="button" class="layui-btn"  id="uploadUrl"   lay-filter="uploadFile">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否热点分类</label>
        <div class="layui-input-block">
            <input type="radio" name="hot" value="1" title="是">
            <input type="radio" name="hot" value="0" title="否" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">热点图片(显示到首页，建议355*355或者668*170)</label>
        <div class="layui-input-block">
            <input type="hidden" name="hotImage"   id="uploadPathH" class="layui-input"     />
            <img id="uploadimgH" src="" width="100" />
            <button type="button" class="layui-btn"  id="uploadUrlH"   lay-filter="uploadFile">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">热点图片显示位置</label>
        <div class="layui-input-block">
            <input type="radio" name="hotPosition" value="1" title="位置一">
            <input type="radio" name="hotPosition" value="2" title="位置二">
            <input type="radio" name="hotPosition" value="3" title="位置三">
            <img id="hotposition" src="../../assets/images/hotposition.png" width="120" />
        </div>
    </div>
 		    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">创建日期</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input name="createDate" placeholder="请输入创建日期" type="text" class="layui-input" maxlength="20"  id="createDate"-->
                   <!--lay-verify="required" required/>-->
        <!--</div>-->
    <!--</div>-->
 		    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">创建人ID</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input name="createId" placeholder="请输入创建人ID" type="text" class="layui-input" maxlength="20"  id="createId"-->
                   <!--lay-verify="required" required/>-->
        <!--</div>-->
    <!--</div>-->
     <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="user-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'config', 'admin', 'form', 'formSelects','upload'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var upload=layui.upload;
        var config = layui.config;

        var quicktestype = admin.getTempData('t_quicktestype');
        // console.log(quicktestype)
           if (quicktestype.method=="update"){
        	//form.val('quicktestype-form', quicktestype);
               admin.formLoad("#quicktestype-form",quicktestype);

        	$("#uploadimg").attr("src",quicktestype.image);
        	$("#uploadimg2").attr("src",quicktestype.titleImage);
        	$("#uploadimgH").attr("src",quicktestype.hotImage);
            form.render();
        }
        // 表单提交事件
        form.on('submit(user-form-submit)', function (data) {
             layer.load(2);
            console.log(data);
            admin.req('business/quicktestype/'+quicktestype.method, JSON.stringify(data.field), function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 1, time: 500});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                }
            }, "post");  
            return false;
        });
        //创建一个上传组件 remarkuploadUrl
        upload.render({
            elem: '#uploadUrl'
            ,url:config.base_server+'file/uploadFile'
            ,accept: "images"
            ,before: function(o){
                console.log(o)
            }
            ,done: function(res, index, upload){ //上传后的回调
                if(res.code==0){
                    $('#uploadimg').attr("src", res.data.url);
                    $('#uploadPath').val(res.data.url);
                }
            }
        });
        //创建一个上传组件 remarkuploadUrl
        upload.render({
            elem: '#uploadUrl2'
            ,url:config.base_server+'file/uploadFile'
            ,accept: "images"
            ,before: function(o){
                console.log(o)
            }
            ,done: function(res, index, upload){ //上传后的回调
                if(res.code==0){
                    $('#uploadimg2').attr("src", res.data.url);
                    $('#uploadPath2').val(res.data.url);
                }
            }
        });
        //创建一个上传组件 hot image
        upload.render({
            elem: '#uploadUrlH'
            ,url:config.base_server+'file/uploadFile'
            ,accept: "images"
            ,before: function(o){
                console.log(o)
            }
            ,done: function(res, index, upload){ //上传后的回调
                if(res.code==0){
                    $('#uploadimgH').attr("src", res.data.url);
                    $('#uploadPathH').val(res.data.url);
                }
            }
        })
    });
</script>
